/*
* @Author: Rosen
* @Date:   2018-01-25 21:21:46
* @Last Modified by:   Rosen
* @Last Modified time: 2018-01-31 13:33:42
*/
import MUtil        from 'util/mm.jsx'

const _mm   = new MUtil();

class User{
    // 用户登录
    login(loginInfo){
        return _mm.request({ //传下面的值给mm.request
            type: 'post',
            url: '/manage/user/login.do',
            data: loginInfo //logininfo是login.jxs传过来的
        });
    }
    // 检查登录接口的数据是不是合法
    checkLoginInfo(loginInfo){
        let username = $.trim(loginInfo.username),
            password = $.trim(loginInfo.password);
        // 判断用户名为空
        if(typeof username !== 'string' || username.length ===0){
            return {
                status: false,
                msg: '用户名不能为空！'
            }
        }
        // 判断密码为空
        if(typeof password !== 'string' || password.length ===0){
            return {
                status: false,
                msg: '密码不能为空！'
            }
        }
        return {
            status : true,
            msg : '验证通过'
        }
    }
    // 退出登录
    logout(){
        return _mm.request({
            type    : 'post',
            url     : '/user/logout.do'
        });
    }
    getUserList(listParam){
       /* return _mm.request({
            type    : 'post',
            url     : '/manage/user/list.do',
            data    : {
                pageNum : pageNum
            }
        });*/

         let url     = '',
            data    = {};
        if(listParam.listType === 'list'){
            url                         = '/manage/user/list.do'; 
            data.pageNum                = listParam.pageNum;
        }else if(listParam.listType === 'search'){  //如果是点了搜索单个用户的功能
            url = '/manage/user/detail.do';
            data.pageNum                = listParam.pageNum;
            data[listParam.searchType]  = listParam.keyword;  //searchType存有usrename ,email关键字. 在user目录index-list-seach.jsx,value="username">里
        } 
        return _mm.request({
            type    : 'post',
            url     : url,
            data    : data
        });

    }
  //修改限制原因
    onUpdateLimit(category){
     return _mm.request({
            type    : 'post',
            url     : '/manage/user/updatalisttext.do',
            data    : category
        });

    }
    
 onUpdateEndTime(category){
     return _mm.request({
            type    : 'post',
            url     : '/manage/user/onUpdateEndTime.do',
            data    : category
        });

    }



      //设置或者取消限制
    onLimit(category){
     return _mm.request({
            type    : 'post',
            url     : '/manage/user/onLimit.do',
            data    : category
        });

    }



}

export default User;